package com.felix.tech.ocms.controller;

import com.felix.tech.ocms.domain.User;
import com.felix.tech.ocms.repository.UserRepository;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import java.util.Map;

@RestController
public class UserController {

    private final UserRepository userRepository;

    @Autowired
    public UserController(UserRepository userRepository) {
        this.userRepository = userRepository;
    }

    @PostMapping("/person/save")
    public User save(@RequestBody Map queryMap){
        final User user = new User();
        final String name = String.valueOf(queryMap.get("name"));
        user.setName(name);
        if (userRepository.save(user)) {
            System.out.println(name + "保存成功。");
        };
        return user;
    }
}
